package com.example.zhouj;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.Map;

import okhttp3.Call;

/**
 * Created by Zhoujian on 2016/10/25 17:27.
 * Email: 1025889325@qq.com
 */

public class NsUri {
    /**
     * 代参数的Get 请求
     * @param uri
     * @param parMap
     * @param myCallBack
     */
    public static void get(String uri,Map<String,String> parMap,final MyCallBack myCallBack){

        OkHttpUtils.get().url(uri).params(parMap).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                myCallBack.error( call,  e,  id);
            }

            @Override
            public void onResponse(String response, int id) {
                myCallBack.ok(response);
            }
        });
    }

    /**
     * 不代参数的Get 请求
     * @param uri
     * @param myCallBack
     */
    public static void get(String uri,final MyCallBack myCallBack){
        OkHttpUtils.get().url(uri).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                myCallBack.error( call,  e,  id);
            }

            @Override
            public void onResponse(String response, int id) {
                myCallBack.ok(response);
            }
            });
    }

    /**
     * Post 请求
     * @param uri
     * @param parMap
     * @param myCallBack
     */
    public static void post(String uri,Map<String,String> parMap,final MyCallBack myCallBack){

        OkHttpUtils.post().url(uri).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                myCallBack.error( call,  e,  id);
            }

            @Override
            public void onResponse(String response, int id) {
                myCallBack.ok(response);
            }
        });
    }


    MyCallBack myCallBack;
    public interface MyCallBack{
        void ok(String data);
        void error(Call call, Exception e, int id);
    }

}




